package leetcode2;

import java.util.Arrays;

public class LongestStrChain {
    public int longestStrChain(String[] words) {
        Arrays.sort(words, (str1, str2) -> str1.length() - str2.length());
        int ans = 1;
        for (int i = 0; i < words.length - 1; i++) {
            String first = words[i];
            String second = words[i + 1];
            if (second.length() - first.length() == 1) {
                int count = 0;
                for (int j = 0; j < first.length() && count < 1; j++) {
                    if (first.charAt(j) != second.charAt(j)) {
                        count++;
                    }
                }
                if (count == 0) {
                    ans++;
                }
            }
        }
        System.out.println(Arrays.toString(words));
        return 0;
    }

    public static void main(String[] args) {
        LongestStrChain longestStrChain = new LongestStrChain();
        longestStrChain.longestStrChain(new String[]{"a", "b", "ba", "bca", "bda", "bdca"});
    }
}
